package com.itheima.admin.kafka;

import com.itheima.admin.service.KafkaService;
import com.itheima.common.constants.BusinessConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
@Slf4j
public class ConsumerWmNews {
    @Autowired
    private KafkaService kafkaService;
    //监听有文章id的主题
    @KafkaListener(topics = BusinessConstants.MqConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void WmNewsListener(ConsumerRecord<String,String> msg){
        String s = UUID.randomUUID().toString();
        try {

            log.info("消费到文章id={},uuid={}，主题={},os={}",msg.value(),s,msg.topic(),msg.offset());
            kafkaService.WmNewsSh(s,Long.valueOf(msg.value()));
        } catch (Exception e) {
            log.info("内容审核异常uuid={},文章id={}",s,msg.value());
        }
    }
}
